package src

import (
	"flag"
	"fmt"
	"gitee.com/baidugoogle/ccu/src/router"
	"gitee.com/baidugoogle/ccu/src/ulog"
	"github.com/gin-gonic/gin"
	"net/http"
)

func VMain() {
	defer func() {
		ulog.Flush()
	}()

	var httpPort = 8080
	flag.IntVar(&httpPort, "port", httpPort, "listener port")
	flag.Parse()

	//gin.SetMode(gin.ReleaseMode)

	var r = gin.Default()
	router.InitRouter(r)

	var server = &http.Server{
		Addr:    fmt.Sprintf(":%v", httpPort),
		Handler: r,
	}

	ulog.Info("listen http on %v", server.Addr)
	if err := server.ListenAndServe(); err != nil {
		ulog.Error("listen http on %v fail %v", server.Addr, err)
	}
}
